%%%-------------------------------------------------------------------
%%% @author Administrator
%%% @copyright (C) 2019, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 14. 10月 2019 18:19
%%%-------------------------------------------------------------------
-module(robotServer_app_assist).
-author("Administrator").
-include("include/logger.hrl").
-define(SUP_NAME, robotServer_sup).

%% API
-export([start/0]).


start() ->
  %%热更
  case myshare:get_env(develop) of
    true ->
      case start_reload() of
        {error, Reason2} ->
          ?ERROR("start erload error ~p\n", [Reason2]),
          throw({reload, Reason2});
        _ ->
          ok
      end;
    _ -> ok
  end,

  %%mysql 底层
  case start_mysql() of
    {error, Reason1} ->
      ?ERROR("start mysql error ~p\n", [Reason1]),
      throw({mysql, Reason1});
    _ ->
      ok
  end,

  %%玩家监督数
  case player_sup() of
    {error, Reason3} ->
      ?ERROR("start player_ws error ~p\n", [Reason3]),
      throw({player_sup, Reason3});
    _ ->
      ok
  end,
  %%main进程
  case start_main() of
    {error, Reason4} ->
      ?ERROR("start mian error ~p\n", [Reason4]),
      throw({main, Reason4});
    _ ->
      ok
  end,

  %%模拟客服端游戏监督数
  case game_sup() of
    {error, Reason5} ->
      ?ERROR("start game_sup error ~p\n", [Reason5]),
      throw({player_sup, Reason5});
    _ ->
      ok
  end,
  case start_webSup() of
    {error, Reason6} ->
      ?ERROR("start start_webSup error ~p\n", [Reason6]),
      throw({start_webSup, Reason6});
    _ ->
      ok
  end,
  case start_random_number() of
    {error, Reason7} ->
      ?ERROR("start_random_number error ~p\n", [Reason7]),
      throw({player_sup, Reason7});
    _ -> ok
  end,
  case start_pool_player() of
    {error, Reason8} ->
      ?ERROR("start_pool_player:~p", [Reason8]),
      throw({player_sup, Reason8});
    _ -> ok
  end,
  case start_schedule() of
    {error, Reason9} ->
      ?ERROR("start_schedule:~p", [Reason9]),
      throw({start_schedule, Reason9});
    _ -> ok
  end,
  ok.

%%mysql进程
start_mysql() ->
  supervisor:start_child(?SUP_NAME, {database, {database, start_link, []}, permanent, 10000, worker, [database]}).

%%热更进程
start_reload() ->
  supervisor:start_child(?SUP_NAME, {reload, {reload, start_link, []}, permanent, 10000, worker, [reload]}).

%%玩家监督树
player_sup() ->
  supervisor:start_child(?SUP_NAME, {player_sup, {player_sup, start_link, []}, permanent, infinity, supervisor, [player_sup]}).

%%公共main进程，定时器
start_main() ->
  supervisor:start_child(?SUP_NAME, {main, {main, start_link, []}, permanent, infinity, worker, [player_sup]}).

%%游戏监督树
game_sup() ->
  supervisor:start_child(?SUP_NAME, {game_sup, {game_sup, start_link, []}, permanent, infinity, supervisor, [game_sup]}).

%%web server
start_webSup() ->
  supervisor:start_child(?SUP_NAME, {netWebSup, {netWebSup, start_link, []}, permanent, 10000, supervisor, [netWebSup]}).

%% random
start_random_number() ->
  supervisor:start_child(?SUP_NAME, {random_number, {random_number, start_link, []}, permanent, infinity, worker, [random_number]}).

%% 账号池
start_pool_player() ->
  supervisor:start_child(?SUP_NAME, {pool_player, {pool_player, start_link, []}, permanent, infinity, worker, [pool_player]}).

%%抢庄调度
start_schedule() ->
  supervisor:start_child(?SUP_NAME, {scheduling, {scheduling, start_link, []}, permanent, infinity, worker, [scheduling]}).









